"use client"
import {aiGenerateQuestionsUsingPost} from "@/api/questionController";
import {Button, Form, Input, InputNumber, message} from "antd";
import React from "react";
import './index.css';
interface Props {
}

/**
 * ai 生成题目页面
 * @param props
 * @constructor
 */
const AiGenerateQuestionPage: React.FC<Props> = (props) => {
    const [form] = Form.useForm();
    const [loading, setLoading] = React.useState(false);

    /**
     * 提交
     *
     * @param value
     */
    const doSubmit = async (value: API.QuestionAiGenerateRequest) => {
        const hide = message.loading("正在操作");
        setLoading(true);
        try {
            await aiGenerateQuestionsUsingPost(value);
            hide();
            message.success("操作成功");
        } catch (error: any) {
            hide();
            message.error("操作失败，" + error.message);
        }
        setLoading(false);
    };


    return (
        <div id={"aiGenerateQuestionPage"}>
            <h2>AI 生成题目</h2>
            <Form form={form} style={{ marginTop: 24 }} onFinish={doSubmit}>
                <Form.Item label="题目方向" name="questionType">
                    <Input placeholder="请输入题目方向"/>
                </Form.Item>
                <Form.Item label="题目数量" name="number">
                    <InputNumber defaultValue={10} max={30} min={1}/>
                </Form.Item>
                <Form.Item>
                    <Button loading={loading} style={{width: 180}} type="primary" htmlType="submit">
                        提交
                    </Button>
                </Form.Item>
            </Form>
        </div>

    );
};
export default AiGenerateQuestionPage;